package com.example.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * @author ChenXiaoBin
 * on 2020-03-03
 */
public class ConfigWrap {
    /**
     * 获取String类型数据
     *
     * @param key key
     * @return value
     */
    public static String getStringValue(String key) {
        try {
            return StringUtils.trim(SpringWrap.getApplicationContent().getEnvironment().getProperty(key));
        } catch (Exception e) {
            return "";
        }
    }

    /**
     * 获取String类型数据
     *
     * @param key          key
     * @param defaultValue 默认值
     * @return value
     */
    public static String getStringValue(String key, String defaultValue) {
        try {
            String value = StringUtils.trim(SpringWrap.getApplicationContent().getEnvironment().getProperty(key));
            return StringUtils.isNotBlank(value) ? value : defaultValue;
        } catch (Exception e) {
            return "";
        }
    }

    /**
     * 获取Integer类型数据
     *
     * @param key key
     * @return value
     */
    public static Integer getIntegerValue(String key) {
        String value = ConfigWrap.getStringValue(key);
        return StringUtils.isBlank(value) ? null : Integer.parseInt(value);
    }
}
